﻿package {

	import flash.text.TextFormat;
	import flash.text.FontType;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	public class SignUp extends MovieClip {
		
		
		private var Background:MovieClip = new BackgroundMC();
		private var signUpText:MovieClip = new signUpTextMC();
		private var SignUpButton:SimpleButton = new signUpBtn();
		private var signUpBox1:MovieClip = new signUpBoxMC();
		private var signUpBox2:MovieClip = new signUpBoxMC();
		private var signUpBox3:MovieClip = new signUpBoxMC();
		private var signUpBox4:MovieClip = new signUpBoxMC();
		private var signUpBox5:MovieClip = new signUpBoxMC();
		private var signUpBox6:MovieClip = new signUpBoxMC();
		
		private var userNameField:TextField = new TextField();
		private var userPasswordField:TextField=new TextField();
		private var userFirstNameField:TextField = new TextField();
		private var userLastNameField:TextField=new TextField();
		private var userAddressField:TextField=new TextField();
		private var userEmailField:TextField=new TextField();
		
		private var newAccountURL:URLRequest=new URLRequest("newAccount.php");
		
		//loader and vars
		private var pageLoader:URLLoader = new URLLoader();
		private var pageVars:URLVariables = new URLVariables();



		public function SignUp() {


			
			addChild(Background);
			addChild(signUpText);
			addChild(signUpBox6);
			addChild(signUpBox5);
			addChild(signUpBox4);
			addChild(signUpBox3);
			addChild(signUpBox2);
			addChild(signUpBox1);
			addChild(SignUpButton);
			addChild(userNameField);
			addChild(userPasswordField);
			addChild(userFirstNameField);
			addChild(userLastNameField);
			addChild(userAddressField);
			addChild(userEmailField);
			
			
			signUpText.x= stage.stageWidth/2 - 200 
			signUpText.y = stage.stageHeight/2 -250;
			
			signUpBox1.x = stage.stageWidth/2 -185
			signUpBox1.y = stage.stageHeight/2 -113
			
			signUpBox2.x = stage.stageWidth/2 -185
			signUpBox2.y = stage.stageHeight/2- 65
			
			signUpBox3.x = stage.stageWidth/2 -185
			signUpBox3.y = stage.stageHeight/2 -17

			signUpBox4.x = stage.stageWidth/2 -185
			signUpBox4.y = stage.stageHeight/2 + 31

			signUpBox5.x = stage.stageWidth/2 -185
			signUpBox5.y = stage.stageHeight/2 +79

			signUpBox6.x = stage.stageWidth/2 -185
			signUpBox6.y = stage.stageHeight/2 +127

			SignUpButton.x=stage.stageWidth/2 + 105
			SignUpButton.y=stage.stageHeight/2 + 165
			SignUpButton.addEventListener(MouseEvent.CLICK,buttonListener);
			
			userNameField.type=TextFieldType.INPUT;
			userNameField.border=true;
			userNameField.height= signUpBox1.height;
			userNameField.width= signUpBox1.width;
			userNameField.x=stage.stageWidth/2-185;
			userNameField.y=stage.stageHeight/2+79;
			userNameField.restrict="a-zA-Z0-9_";
			userNameField.height = 20;
			
			userPasswordField.type=TextFieldType.INPUT;
			userPasswordField.border=true;
			userPasswordField.height= signUpBox1.height;
			userPasswordField.width= signUpBox1.width;
			userPasswordField.x=stage.stageWidth/2-185;
			userPasswordField.y=stage.stageHeight/2+127;
			userPasswordField.restrict="a-zA-Z0-9_";
			userPasswordField.height = 20;
			
			userFirstNameField.type=TextFieldType.INPUT;
			userFirstNameField.border=true;
			userFirstNameField.height= signUpBox1.height;
			userFirstNameField.width= signUpBox1.width;
			userFirstNameField.x=stage.stageWidth/2-185;
			userFirstNameField.y=stage.stageHeight/2-113;
			userFirstNameField.restrict="a-zA-Z0-9_";
			userFirstNameField.height = 20;
			
			userLastNameField.type=TextFieldType.INPUT;
			userLastNameField.border=true;
			userLastNameField.height= signUpBox1.height;
			userLastNameField.width= signUpBox1.width;
			userLastNameField.x=stage.stageWidth/2-185;
			userLastNameField.y=stage.stageHeight/2-65;
			userLastNameField.restrict="a-zA-Z0-9_";
			userLastNameField.height = 20;
			
			userAddressField.type=TextFieldType.INPUT;
			userAddressField.border=true;
			userAddressField.height= signUpBox1.height;
			userAddressField.width= signUpBox1.width;
			userAddressField.x=stage.stageWidth/2-185;
			userAddressField.y=stage.stageHeight/2-17;
			userAddressField.restrict="a-zA-Z0-9_";
			userAddressField.height = 20;
			
			userEmailField.type=TextFieldType.INPUT;
			userEmailField.border=true;
			userEmailField.height= signUpBox1.height;
			userEmailField.width= signUpBox1.width;
			userEmailField.x=stage.stageWidth/2-185;
			userEmailField.y=stage.stageHeight/2+31;
			userEmailField.restrict="a-zA-Z0-9_@.";
			userEmailField.height = 20;
			
		}

		function buttonListener(event:MouseEvent):void {

			newAccount(userNameField.text,userPasswordField.text,userLastNameField.text,userFirstNameField.text/*userEmailField.text,userAddressField.text*/);
		}



		function newAccount(user,pass,fname,lname) {
			if (user!=""&&pass!=""&&fname!=""&&lname!=""/*&&email!=""&&address!=""*/) {
	
				pageVars.user=user;
				pageVars.pass=pass;
				pageVars.fname=fname;
				pageVars.lname=lname;
				//pageVars.email=email;
				//pageVars.address=address;
				
				newAccountURL.method=URLRequestMethod.POST;


				newAccountURL.data=pageVars;
				//pageLoader.dataFormat=URLLoaderDataFormat.VARIABLES;

				pageLoader.load(newAccountURL);
	
			}
		}


		//function loadPageSuccessful(event:Event):void {

		// var newVars:URLVariables=new URLVariables(pageLoader.data);
		//switch (newVars.loginStatus) {
		//case 'success' :
		//statusText.text="Tooooooool";
		//break;
		//case 'fail' :
		//statusText.text="DDDooooooool";
		//break;

		//}





	}
}